#leetcode题目101：对称二叉树
#难度：简单
#时间复杂度：O(n)
#空间复杂度：O(n)
#方法：递归

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        def dfs(left,right):
            if not left and not right:
                return True
            if not left or not right:
                return False
            return left.val==right.val and dfs(left.left,right.right) and dfs(left.right,right.left)
        return dfs(root.left,root.right)

#测试数据
root=[1,2,2,3,4,4,3]
root=TreeNode(1,TreeNode(2,TreeNode(3,None,None),TreeNode(4,None,None)),TreeNode(2,TreeNode(4,None,None),TreeNode(3,None,None)))
#预期输出：True
solution=Solution()
print(solution.isSymmetric(root))

root=[1,2,2,None,3,None,3]
root=TreeNode(1,TreeNode(2,None,TreeNode(3,None,None)),TreeNode(2,None,TreeNode(3,None,None)))
#预期输出：False
solution=Solution()
print(solution.isSymmetric(root))